import '../scss/common.scss';
import {
  IndexModel
} from '../models';

//管理公共类
class App {
  //$, options 来源于 Index 类 super()
  constructor($, app, options) {
    this.$app = $('<div id="app"></div>');
    this.swiper = options.swiper;
    this.phone = options.phone;
    this.field = options.field;
    this.cache = null;

    this.init();

  }

  async init() {
    await this.getDatas();
    this.render();
  }

  async getDatas() {
    const indexModel = new IndexModel();

    // await indexModel.getDatas({
    //     swiper: this.swiper,
    //     phone: this.phone,
    //     field: this.field
    //   })
    //   .then((res) => {
    //     this.cache = {
    //       phoneDatas: res.phone_data,
    //       fieldDatas: res.field_data,
    //       swiperDatas: res.swiper_data
    //     }
    //   });

    const data = await indexModel.getDatas({
      swiper: this.swiper,
      phone: this.phone,
      field: this.field
    });

    this.cache = {
      phoneDatas: data.phone_data || null,
      fieldDatas: data.field_data || null,
      swiperDatas: data.swiper_data || null
    }

    /**
     * console.log(res);
     * phone_data:{
     *   field_data:[{},{},...],
     *   phone_data:[{},{},...],
     *   swiper_data:[{},{},...]
     * }
     */
  }

}

export {
  App
};